Skip to content

Conversation

@potrue
Copy link
Owner

@potrue potrue commented Aug 18, 2025

permuteHelper(result, nums, 0);
return result;
}
void permuteHelper(vector<vector<int>>& result, vector<int>& nums, int decided_until) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private でも問題ないでしょうか。

results は出力なので引数の最後にした方が良いかもしれません。
https://google.github.io/styleguide/cppguide.html#Inputs_and_Outputs

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

privateで良いと思います。入れるのを忘れてしまっていました。
出力を最後に持ってくるのが推奨されているというのは知りませんでした。ありがとうございます。

Copy link

@ryosuketc ryosuketc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

よいと思います

permuteHelper(result, nums, 0);
return result;
}
void permuteHelper(vector<vector<int>>& result, vector<int>& nums, int decided_until) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

細かいですが、private 忘れでしょうか。

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

あ、失念していました。

for (int i = decided_until; i < nums.size(); ++i) {
swap(nums[decided_until], nums[i]);
permuteHelper(result, nums, decided_until + 1);
swap(nums[decided_until], nums[i]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

decided_until は swap_index のように感じました。ここまで決めたんだという意味は落ちてしまいますが、、、

swap(nums[decided_until], nums[i]);
}
}
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

重複を含む入力に対して正しく(重複は含まれる)動くのはこのコードだけでしょうか。

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

たしかに、その視点はありませんでした。setを使った解法は動かないように思います。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants